package com.dragon.myapplication.padings;

import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

@Database(entities = {Student.class},version = 1,exportSchema = false)
public abstract class StudentsDataBase extends RoomDatabase {
    private static volatile StudentsDataBase INSTANCE;

    public static StudentsDataBase getInstance(Context context){
        //双重校验 减少锁带来的性能开销 懒汉式单例
        if (INSTANCE == null){
            synchronized(StudentsDataBase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
                                 StudentsDataBase.class, "students.db").build();
                }
            }
        }
        return INSTANCE;
    }

    public abstract StudentDao getStudentDao();
}
